import request from '../request-axios.js';
import { API_CONFIG } from '../config.js';

// 遥测数据列表管理API - 根据API文档更新
export const telemetryDataListAPI = {
  // 查询任务管理列表
  getTelemetryDataList: (params = {}) => {
    return request.get(API_CONFIG.ENDPOINTS.TELEMETRY_DATA_PAGE_LIST, null, { params });
  },
  // 删除任务管理（支持单个ID或ID数组）
  deleteTelemetryData: (idOrIds) => {
    // 统一处理单个ID和ID数组
    let idsParam;
    if (Array.isArray(idOrIds)) {
      // 批量删除：数组转换为逗号拼接字符串
      idsParam = idOrIds.join(',');
    } else {
      // 单个删除：直接使用ID
      idsParam = idOrIds;
    }
    return request.get(API_CONFIG.ENDPOINTS.TELEMETRY_DATA_DELETE, null, { params: { id: idsParam } });
  },
  // 获取任务详情
  getAdminDetail: (id) => {
    return request.post(API_CONFIG.ENDPOINTS.ADMIN_DETAIL, null, { params: { id } });
  },
  
  // 批量保存遥测数据
  batchSaveTelemetryData: (dataList) => {
    return request.post(API_CONFIG.ENDPOINTS.BATCH_SAVE_TELEMETRY_DATA, dataList);
  },

  saveOrCancelTelemetry: (params = {}) => {
    return request.get(API_CONFIG.ENDPOINTS.SAVE_OR_CANCEL_TELEMETRY, null, { params });
  },
  //获取遥测数据文件保存路径
  getTelemetryStoragePath: (params = {}) => {
    return request.get(API_CONFIG.ENDPOINTS.GET_TELEMETRY_STORAGE_PATH, null, { params});
  },

  //编辑遥测数据文件保存路径
  editTelemetryData: (dataList) => {
    return request.post(API_CONFIG.ENDPOINTS.EDIT_TELEMETRY_DATA, dataList);
  }
};

export default telemetryDataListAPI;
